<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('菜单列列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>菜单名称：</p>
                                <input type="text" name="menuName"/>
                            </li>
<!--                            <li>-->
<!--                                <p>描述：</p>-->
<!--                                <input type="text" name="menuDescription"/>-->
<!--                            </li>-->
                            <li>
                                <p>菜单状态：</p>
                                <select name="menuStatus" th:with="type=${@dict.getType('menu_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="wechatprogram:menu:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary multiple disabled" onclick="$.operate.batchUp()" shiro:hasPermission="wechatprogram:menu:batchUp">
                    <i class="fa fa-edit"></i> 批量上架
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.batchDown()" shiro:hasPermission="wechatprogram:menu:batchDown">
                    <i class="fa fa-remove"></i> 批量下架
                </a>
<!--                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="wechatprogram:menu:export">-->
<!--                    <i class="fa fa-download"></i> 导出-->
<!--                 </a>-->
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table" data-mobile-responsive="true"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('wechatprogram:menu:edit')}]];
        var removeFlag = [[${@permission.hasPermi('wechatprogram:menu:remove')}]];
        var menuStatusDatas = [[${@dict.getType('menu_type')}]];
        var publishStatusFlag = [[${@permission.hasPermi('wechatprogram:menu:publish')}]];
        var unPublishStatusFlag = [[${@permission.hasPermi('wechatprogram:menu:unpublish')}]];
        var prefix = ctx + "wechatprogram/menu";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                batchUpUrl: prefix + "/batchUp",
                batchDownUrl: prefix + "/batchDown",
                exportUrl: prefix + "/export",
                modalName: "菜单列",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'id',
                    title : '主键',
                    visible: false
                },
                {
                    field : 'menuName',
                    title : '菜单名称'
                },
                {
                    field: 'menuPictureUrl',
                    title: '菜单图片',
                    formatter: function (value, row, index) {
                        return '<img src="' + value + '" width="150" height="100">';
                    }
                },
                {
                    field : 'menuDescription',
                    title : '描述'
                },
                {
                    field : 'remark',
                    title : '备注'
                },
                {
                    field : 'menuStatus',
                    title : '商品状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(menuStatusDatas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        if(2 == row.menuStatus){
                            actions.push('<a class="btn btn-primary btn-xs ' + publishStatusFlag + '" href="javascript:void(0)" onclick="publish(\'' + row.id +'\',\''+ row.menuName +  '\')"><i class="fa fa-edit"></i>上架</a> ');
                        }
                        if(1 == row.menuStatus){
                            actions.push('<a class="btn btn-danger btn-xs ' + unPublishStatusFlag + '" href="javascript:void(0)" onclick="unpublish(\'' + row.id +'\',\''+ row.menuName + '\')"><i class="fa fa-edit"></i>下架</a> ');
                        }
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');

                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function publish(id,menuName) {
            $.modal.confirm("确定上架：" + menuName + "吗？", function () {
                var url = prefix + "/publishMenu/" + id;
                $.operate.submit(url, "post");
            });
        }

        function unpublish(id,menuName) {
            $.modal.confirm("确定下架：" + menuName + "吗？", function () {
                var url = prefix + "/unPublishMenu/" + id;
                $.operate.submit(url, "post");
            });
        }

    </script>
</body>
</html>